//
//  ChartCanvas.h
//  ChartRefactor
//
//  Created by CaoJun on 15/3/9.
//  Copyright (c) 2015年 CaoJun. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>

typedef NS_ENUM(NSInteger, ChartCanvasTextAnchor) {
    LeftBottom = 0,
    LeftMiddle,
    LeftTop,
    CenterTop,
    CenterMiddle,
    CenterBottom,
    RightTop,
    RightMiddle,
    RightBottom
};

typedef NS_ENUM(NSInteger, LinearGradientDirection) {
    LinearGradientFromLeftToRight = 0,
    LinearGradientFromRightToLeft,
    LinearGradientFromUpToBottom,
    LinearGradientFromBottomToUp
};

//只能在drawRect周期内使用
@interface ChartCanvas : NSObject

@property (nonatomic, assign) CGContextRef context;
@property (nonatomic, assign) CGRect bounds;

-(void) save;
-(void) restore;

//TODO ("setFillPattern")
-(void) setLineWidth:(CGFloat) width;
-(void) setLineCap:(CGLineCap) cap;
-(void) setLineJoin:(CGLineJoin) join;
-(void) setFillStyle:(NSString *) color;
-(void) setFillColor:(UIColor *) color;
-(void) setStrokeStyle:(NSString *) color;
- (void)setStrokeColor:(UIColor *)color;

-(void) drawLineWithX1:(CGFloat) x1 withY1:(CGFloat) y1 withX2:(CGFloat) x2 withY2:(CGFloat) y2;
-(void) drawLineWithLineWidth:(CGFloat) lineWidth WidthLineColor:(NSString *) lineColor  withX1:(CGFloat) x1 withY1:(CGFloat) y1 withX2:(CGFloat) x2 withY2:(CGFloat) y2;

-(void) drawLines:(NSArray * )points;
-(void) drawLinesWithLineWidth:(CGFloat) lineWidth WidthLineColor:(NSString *) lineColor withPoints:(NSArray * )points;

-(void) drawDashedWithLength:(CGFloat[]) lengths withSize:(size_t) size withX1:(CGFloat) x1 withY1:(CGFloat) y1 withX2:(CGFloat) x2 withY2:(CGFloat) y2;
- (void)drawDashLineWidth:(CGFloat)width color:(NSString *)color x1:(CGFloat)x1 y1:(CGFloat)y1 x2:(CGFloat)x2 y2:(CGFloat)y2;

-(void) storkeRectWithX:(CGFloat) x withY:(CGFloat) y withWidth:(CGFloat) width withHeight:(CGFloat) height;
-(void) storkeRect:(CGRect) rect;
-(void) storkeRectWithX:(CGFloat) x withY:(CGFloat) y withWidth:(CGFloat) width withHeight:(CGFloat) height withStrokeColor: (NSString *) color;
-(void) storkeRect:(CGRect) rect withStrokeColor: (NSString *) color;

-(void) fillRectWithX:(CGFloat) x withY:(CGFloat) y withWidth:(CGFloat) width withHeight:(CGFloat) height;
-(void) fillRect:(CGRect) rect;
-(void) fillRectWithX:(CGFloat) x withY:(CGFloat) y withWidth:(CGFloat) width withHeight:(CGFloat) height withFillColor:(NSString *) color;
-(void) fillRect:(CGRect) rect withFillColor:(NSString *) color;

-(void) fillRectWithX1:(CGFloat) x1 withY1:(CGFloat) y1 withX2:(CGFloat) x2 withY2:(CGFloat) y2;
-(void) fillRectWithX1:(CGFloat) x1 withY1:(CGFloat) y1 withX2:(CGFloat) x2 withY2:(CGFloat) y2 withFillColor:(NSString *) color;

-(void) fillPath:(NSArray * )points;
-(void) fillPath:(NSArray * )points withFillColor:(NSString *) color;

-(void) drawRectWithX1:(CGFloat) x1 withY1:(CGFloat) y1 withX2:(CGFloat) x2 withY2:(CGFloat) y2 withLineWidth:(CGFloat) lineWidth withLineColor:(NSString *) color;

-(void) storkeRectLeftBottomWithX:(CGFloat) x withY:(CGFloat) y withWidth:(CGFloat) width withHeight:(CGFloat) height;
-(void) storkeRectLeftBottom:(CGRect) rect;
-(void) storkeRectLeftBottomWithX:(CGFloat) x withY:(CGFloat) y withWidth:(CGFloat) width withHeight:(CGFloat) height withStrokeColor: (NSString *) color;
-(void) storkeRectLeftBottom:(CGRect) rect withStrokeColor: (NSString *) color;

-(void) fillRectLeftBottomWithX:(CGFloat) x withY:(CGFloat) y withWidth:(CGFloat) width withHeight:(CGFloat) height;
-(void) fillRectLeftBottom:(CGRect) rect;
-(void) fillRectLeftBottomWithX:(CGFloat) x withY:(CGFloat) y withWidth:(CGFloat) width withHeight:(CGFloat) height withFillColor:(NSString *) color;
-(void) fillRectLeftBottomWithX:(CGFloat) x withY:(CGFloat) y withWidth:(CGFloat) width withHeight:(CGFloat) height withFillUIColor:(UIColor *) color;
-(void) fillRectLeftBottom:(CGRect) rect withFillColor:(NSString *) color;

-(void) fillCircleWithX:(CGFloat) x withY:(CGFloat) y withRadius:(CGFloat) radius;
-(void) fillCircleWithX:(CGFloat) x withY:(CGFloat) y withRadius:(CGFloat) radius withFillColor:(NSString *) color;

-(void) storkeCircleWithX:(CGFloat) x withY:(CGFloat) y withRadius:(CGFloat) radius;
-(void) storkeCircleWithX:(CGFloat) x withY:(CGFloat) y withRadius:(CGFloat) radius withFillColor:(NSString *) color;

-(void) fillDonutWithX:(CGFloat) x withY:(CGFloat) y withInnerRadius:(CGFloat) innerRadius withOuterRadius:(CGFloat) outerRadius;
-(void) fillDonutWithX:(CGFloat) x withY:(CGFloat) y withInnerRadius:(CGFloat) innerRadius withOuterRadius:(CGFloat) outerRadius withFillColor:(NSString *) color;

-(void) clipToRect:(CGRect) rect;

-(CGRect) getTextRect:(NSString *) text withFont:(NSString *) font withSize:(CGFloat) size;

-(CGRect) fillText:(NSString *) text withX:(CGFloat) x withY:(CGFloat) y withColor:(NSString *) color withFont:(NSString *) font withSize:(CGFloat) size;
-(CGRect) fillText:(NSString *) text withX:(CGFloat) x withY:(CGFloat) y withColor:(NSString *) color withFont:(NSString *) font withSize:(CGFloat) size withAnchor:( ChartCanvasTextAnchor) anchor;
-(CGRect) fillTexts:(NSArray *) texts withX:(CGFloat) x withY:(CGFloat) y withColors:(NSArray *) colors withFonts:(NSArray *) fonts withSizes:(NSArray*) sizes withAnchor:(ChartCanvasTextAnchor) anchor;
- (CGRect)fillAttributedString:(NSAttributedString *)attributedString atPoint:(CGPoint)point anchor:(ChartCanvasTextAnchor)anchor;

+ (CGFloat) colorComponentFrom: (NSString *) string start: (NSUInteger) start length: (NSUInteger) length;

+ (UIColor *) colorWithHexString: (NSString *) hexString;

+ (NSArray *) colorsWithHexString: (NSString *) hexString count:(NSInteger )count sortDir:(NSInteger)sortDir;

- (void) fillHJJTTexts:(NSString *)text withCGRect:(CGRect)rect withColor:(NSString *)color withFontName:(NSString *)font withSize:(NSString *)size withAnchor:(ChartCanvasTextAnchor) anchor;//描绘文字

- (void)drawLinearGradientInRect:(CGRect)pathRect direction:(LinearGradientDirection)direction startColor:(NSString *)startColor endColor:(NSString *)endColor;//横向或纵向 线性渐进图

@end

